package org.coody.gitee.fuzzer;

import org.coody.gitee.entity.GiteeEntity;
import org.coody.gitee.exception.EmailRegisterException;
import org.coody.gitee.exception.FuzzerException;
import org.coody.gitee.fuzzer.iface.GiteeFuzzer;
import org.coody.gitee.util.HttpUtil;
import org.coody.gitee.util.HttpUtil.HttpEntity;

public class EmailCreateFuzzer extends GiteeFuzzer {


	private String createCookie() {
		HttpUtil.HttpEntity httpEntity = HttpUtil.Get("http://mail.bccto.me/");
		return httpEntity.getCookie();
	}


	@Override
	public void fuzzer(GiteeEntity giteeEntity) throws FuzzerException {
		String cookie=createCookie();
		String url = "http://mail.bccto.me/applymail";
		String email = giteeEntity.getAccount() + "@mail.bccto.me";
		String data = "mail=" + email;
		HttpEntity entity = HttpUtil.Post(url, data, 15000, cookie);
		if (!entity.getHtml().contains("\"success\":\"true\"")) {
			throw new EmailRegisterException("邮箱申请失败>>" + email+":"+entity.getHtml());
		}
		System.out.println("申请邮箱>>" + email);
		giteeEntity.setEmail(email);
	}
}
